#include "Utils.hh"
#include "BankSystem.hh"
#include "Account.hh"

using namespace BankSystem;

// 取款操作
void performWithdrawal(const std::shared_ptr<CheckingAccount>& account) {
    system("clear");
    SetConsoleOutputCP(CP_UTF8);
    std::cout << "===== Withdraw from Account: " << account->getAccountId() << " =====" << std::endl;
    std::cout << "Current Balance: " << Utils::formatCurrency(account->getBalance()) << "\n" << std::endl;
    
    double amount;
    std::cout << "Enter amount to withdraw: ";
    std::cin >> amount;
    clearInputBuffer();
    
    std::string note;
    std::cout << "Add note (optional): ";
    std::getline(std::cin, note);
    
    if (account->withdraw(amount, note)) {
        std::cout << "\nWithdrawal successful!" << std::endl;
        std::cout << "New balance: " << Utils::formatCurrency(account->getBalance()) << std::endl;
        std::cout << "Transaction ID: " << account->getTransactions().back()->getTransactionId() << " has been recorded." << std::endl;
    }
    
    waitForEnter();
}
